<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>绑定第三方账号</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <!--[if lt IE 9]>
    <script th:src="@{/js/IE9/html5.min.js}"></script>
    <script th:src="@{/js/IE9/respond.min.js}"></script>
    <![endif]-->
    <style>
        html, body {
            width: 100%;
            height: 100%;
            overflow: hidden
        }

        body {
            background: #1E9FFF;
        }

        body:after {
            content: '';
            background-repeat: no-repeat;
            background-size: cover;
            -webkit-filter: blur(3px);
            -moz-filter: blur(3px);
            -o-filter: blur(3px);
            -ms-filter: blur(3px);
            filter: blur(3px);
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: -1;
        }

        .layui-container {
            width: 100%;
            height: 100%;
            overflow: hidden
        }

        .admin-login-background {
            width: 500px;
            height: 300px;
            position: absolute;
            left: 43%;
            top: 35%;
            margin-left: -180px;
            margin-top: -100px;
        }

        .logo-title {
            text-align: center;
            letter-spacing: 2px;
            padding: 14px 0;
        }

        .logo-title h1 {
            color: #1E9FFF;
            font-size: 25px;
            font-weight: bold;
        }

        .login-form {
            background-color: #fff;
            border: 1px solid #fff;
            border-radius: 3px;
            padding: 14px 20px;
            box-shadow: 0 0 8px #eeeeee;
        }

        .login-form .layui-form-item {
            position: relative;
        }

        .layui-form-label {
            width: 120px;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="layui-form login-form">
            <form class="layui-form" action="" method="post">
                <div class="layui-form-item logo-title">
                    <h1>绑定第三方账号</h1>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">第三方平台:</label>
                    <div class="layui-input-inline">
                        <input type="text"
                               name="source"
                               th:value="${param.source}"
                               placeholder="请输入第三方平台" value="" class="layui-input"
                               lay-verify="required|pass" readonly>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">第三方平台用户名:</label>
                    <div class="layui-input-inline">
                        <input type="text"
                               name="socialUsername"
                               th:value="${param.socialUsername}"
                               placeholder="请输入第三方平台用户名" value="" class="layui-input"
                               lay-verify="required|pass" readonly>
                    </div>
                </div>
                <input type="text"
                       name="uuid"
                       th:value="${param.uuid}"
                       placeholder="请输入第三方平台uuid" class="layui-input layui-hide"
                       lay-verify="required" readonly>
                <div class="layui-form-item">
                    <label class="layui-form-label">MyBlog账号:</label>
                    <div class="layui-input-inline">
                        <input type="text"
                               name="username"
                               placeholder="请输入用户名" value="" class="layui-input"
                               lay-verify="required|pass" hidden required>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码:</label>
                    <div class="layui-input-inline">
                        <input type="text"
                               name="password"
                               placeholder="请输入密码" hidden value="" class="layui-input"
                               lay-verify="required|pass" required>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-normal" lay-submit=""
                            lay-filter="login" style="width:60%;margin-left: 20%">绑 定
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<script th:src="@{/js/jquery/jquery.min.js}" charset="utf-8"></script>
<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/js/jq-module/jquery.particleground.min.js}" charset="utf-8"></script>
<script type="text/javascript" th:inline="javascript">
    let basePath = [[${#httpServletRequest.getContextPath()}]];

    window.onload = (function () {
        let HandlerInterceptor = [[${Interceptor_msg}]];
        let login_msg = [[${session.login_msg}]];
        let Auth_msg = [[${errorMsg}]]
        if (login_msg != "" && null != login_msg) {
            layui.layer.msg(login_msg);
        }
        if (HandlerInterceptor != "" && null != HandlerInterceptor) {
            layui.layer.msg(HandlerInterceptor);
        }
        if (Auth_msg != "" && null != Auth_msg) {
            layui.layer.msg(Auth_msg);
        }
    });
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;
        // 粒子线条背景
        $(document).ready(function () {
            $('.layui-container').particleground({
                dotColor: '#7ec7fd',
                lineColor: '#7ec7fd'
            });
        });

        // 进行登录操作
        form.on('submit(login)', function (data) {
            data = data.field;
            if (data.username == '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (data.password == '') {
                layer.msg('密码不能为空');
                return false;
            }
            let bindLayer;
            bindLayer = layui.layer.msg('正在绑定！', {icon: 16, shade: 0.01, time: 0});
            $.ajax({
                type: "POST",
                url: basePath + '/oauth/binding',
                data: {
                    "username": data.username,
                    "password": data.password,
                    "source": data.source,
                    "uuid": data.uuid
                },
                success: function (result) {
                    layui.layer.close(bindLayer);
                    console.log(result);
                    let jsonData = JSON.parse(result);
                    if (jsonData.code == 1) {
                        //成功
                        layui.layer.msg(jsonData.msg, {icon: 1, time: 1000}, function () {
                            parent.window.location = basePath + '/user/toArticle';
                        });
                    } else {
                        //失败
                        layer.msg(jsonData.msg, {icon: 2});
                    }
                },
                error: function (arg) {
                    layui.layer.close(bindLayer);
                    layer.msg(arg);
                }
            });
            return false;
        });
    });
</script>
</body>
</html>